package com.sjp.entity;

import com.sjp.test.TestReaderMap;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Brand extends Component {
    // 卡片名称
    private String name;
    // 卡片状态： 灰色ture 高亮false
    private boolean isGray;

    // 高亮图片
    private Image image;
    // 灰色图片
    private Image grayImage;

    // 设置图片 x、y轴
    private Integer x;
    private Integer y;

    // 设置宽度和高度
    private Integer width;
    private Integer height;



    private Cell cell;

    private EleBox eleBox = new EleBox();


    // 定义一个构造方法给卡片名称赋值
    public Brand(String name){
        this.name = name;
        // 设置默认(高亮)卡片、灰色卡片
        this.image = Toolkit.getDefaultToolkit().getImage("imgs/"+name+".png");
        this.grayImage = Toolkit.getDefaultToolkit().getImage("imgs/"+name+"_gray.png");
        this.isGray = false;//设置默认状态为高亮
        // 设置宽高
        this.width = 50;
        this.height = 50;
        this.x = 0;
        this.y = 0;

        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.print("点击了：");
                Brand b = (Brand) e.getSource();
                if (b.isGray()){
                    return;
                }else {
//                    b.getParent().remove(b);


                    cell.setState(0);
                    cell.setBrand(null);

                    eleBox.add(b);
                    System.out.println(b.getName());
                    TestReaderMap.m.compareAll();
                }

            }
        });

    }

    // 绘制图片到窗口中


    @Override
    public void paint(Graphics g) {
        // super.paint(g);
        if(isGray == true){
            g.drawImage(this.grayImage,this.x,this.y,null);
        }else{
            g.drawImage(this.image,this.x,this.y,null);
        }
//        repaint();
    }

    // 快捷键alt+insert快捷创建get set方法

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    public boolean isGray() {
        return isGray;
    }

    public void setGray(boolean gray) {
        isGray = gray;
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public Image getGrayImage() {
        return grayImage;
    }

    public void setGrayImage(Image grayImage) {
        this.grayImage = grayImage;
    }
    public Cell getCell() {
        return cell;
    }

    public void setCell(Cell cell) {
        this.cell = cell;
    }
}
